package com.css.fxfzaqbz.modules.data.service.impl;

import com.css.fxfzaqbz.modules.assess.entity.CasualtiesEntity;
import com.css.fxfzaqbz.modules.assess.entity.DisasterAssEntity;
import com.css.fxfzaqbz.modules.assess.entity.RiskAssessmentEntity;
import com.css.fxfzaqbz.modules.assess.entity.SecondDisastersEntity;
import com.css.fxfzaqbz.modules.assess.repository.CasualtiesRepository;
import com.css.fxfzaqbz.modules.assess.repository.DisasterRepository;
import com.css.fxfzaqbz.modules.assess.repository.RiskAssessmentRepository;
import com.css.fxfzaqbz.modules.assess.repository.SecondDisastersRepository;
import com.css.fxfzaqbz.modules.assess2.entity.KeyplaceRiskassessment;
import com.css.fxfzaqbz.modules.assess2.entity.TaskContent;
import com.css.fxfzaqbz.modules.assess2.entity.UrgencysettleData;
import com.css.fxfzaqbz.modules.assess2.repository.KeyplaceRiskassessmentRepository;
import com.css.fxfzaqbz.modules.assess2.repository.UrgencysettleDataRepository;
import com.css.fxfzaqbz.modules.data.entity.IASeismicAssess;
import com.css.fxfzaqbz.modules.data.repository.IASeismicAssessRepository;
import com.css.fxfzaqbz.modules.data.service.IASeismicAssessService;
import com.css.fxfzaqbz.util.PlatformDateUtils;
import com.css.fxfzaqbz.util.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

@Service
public class IASeismicAssessServiceImpl implements IASeismicAssessService {

    @Autowired
    IASeismicAssessRepository iaSeismicAssessRepository;
    @Resource
    KeyplaceRiskassessmentRepository keyplaceRiskassessmentRepository;
    @Resource
    UrgencysettleDataRepository urgencysettleDataRepository;
    @Resource
    CasualtiesRepository casualtiesRepository;
    @Resource
    DisasterRepository disasterRepository;
    @Resource
    SecondDisastersRepository secondDisastersRepository;
    @Resource
    RiskAssessmentRepository riskAssessmentRepository;

    @Override
    public IASeismicAssess saveIASeismicAssess(IASeismicAssess iaSeismicAssess) {
        iaSeismicAssess.setSaId(UUIDGenerator.getUUID());
        return iaSeismicAssessRepository.saveIASeismicAssess(iaSeismicAssess);
    }

    @Override
    public List<IASeismicAssess> getIASeismicAssesses(String id) {
        return iaSeismicAssessRepository.getIASeismicAssesses(id);
    }

    @Override
    public IASeismicAssess getASeismicAssessById(String id) {
        return iaSeismicAssessRepository.getASeismicAssessById(id);
    }

    @Override
    public IASeismicAssess updateIASeismicAssess(IASeismicAssess iaSeismicAssess) {
        iaSeismicAssess.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        return iaSeismicAssessRepository.updateIASeismicAssess(iaSeismicAssess);
    }

    @Override
    public void delIASeismicAssess(List<String> ids, String userID) {
        Timestamp timestamp = PlatformDateUtils.getCurrentTimestamp();
        iaSeismicAssessRepository.delIASeismicAssess(ids, timestamp, userID);
    }

    @Override
    public List<IASeismicAssess> getIASeismicAssessByTask(String iaId, String taskName) {
        return iaSeismicAssessRepository.getIASeismicAssessByTask(iaId, taskName);
    }

    @Override
    public List<TaskContent> getByActiveId(String id) {
        //重点场所风险评估
        List<TaskContent> keyplaceRiskassessment = keyplaceRiskassessmentRepository.getKeyplaceRiskassessmentByRelation1(id);
        //需紧急安置人员
        List<TaskContent> urgencysettleData = urgencysettleDataRepository.getUrgencysettleData1(id);
        //人口伤亡评估
        List<TaskContent> Casualties = casualtiesRepository.getAllCasualties1(id);
        //房屋地震灾害风险评估
        List<TaskContent> DisasterAss = disasterRepository.getAllDisasterAss1(id);
        //次生灾害隐患评估
        List<TaskContent> SecondDisasters = secondDisastersRepository.getAllSecondDisasters1(id);
        //地震危险性评估
        List<TaskContent> RiskAssessment = riskAssessmentRepository.getAllRiskAssessment1(id);
        List<TaskContent> list = new ArrayList<>();
        for (TaskContent keyplaceRiskass : keyplaceRiskassessment) {
            if (keyplaceRiskass!=null){
                keyplaceRiskass.setTaskName("重点场所风险评估");
            }
            list.add(keyplaceRiskass);
        }
        for (TaskContent urgencysettleDatum : urgencysettleData) {
            if (urgencysettleDatum!=null){
                urgencysettleDatum.setTaskName("需紧急安置人员");
            }
            list.add(urgencysettleDatum);
        }
        for (TaskContent casualty : Casualties) {
            if (casualty!=null){
                casualty.setTaskName("人口伤亡评估");
            }
            list.add(casualty);
        }
        for (TaskContent disasterAss : DisasterAss) {
            if (disasterAss!=null){
                disasterAss.setTaskName("房屋地震灾害风险评估");
            }
            list.add(disasterAss);
        }
        for (TaskContent secondDisaster : SecondDisasters) {
            if (secondDisaster!=null){
                secondDisaster.setTaskName("次生灾害隐患评估");
            }
            list.add(secondDisaster);
        }
        for (TaskContent riskAssessmentEntity : RiskAssessment) {
            if (riskAssessmentEntity!=null){
                riskAssessmentEntity.setTaskName("地震危险性评估");
            }
            list.add(riskAssessmentEntity);
        }
        return list;
    }
}
